#include "lcd.h"

//类的静态数据成员必须在类外初始化   nullptr -void*    C:NULL---#define NULL (void)0  C++:NULL 0
Lcd* Lcd::instance = NULL;



Lcd::Lcd(const char*deviceName)
{
    //构造函数存放初始化
    memset(m_lcdDeviceName,0,sizeof(m_lcdDeviceName));
    memcpy(m_lcdDeviceName,deviceName,strlen(deviceName));

    //打开液晶屏
    lcdFd = open(m_lcdDeviceName,O_RDWR);
    if(lcdFd == -1)
    {
        perror("open lcd error");
        return ;
    }
    //内存映射
    lcd_p = (int*)mmap(NULL,LCD_SIZE,PROT_READ|PROT_WRITE,MAP_SHARED,lcdFd,0);
    if(lcd_p == MAP_FAILED)
    {
        perror("mmap error");
        return ;
    }


}
Lcd::~Lcd()
{
    //解除映射
    munmap(lcd_p,LCD_SIZE);
    lcd_p = NULL;

    close(lcdFd);
}

int *Lcd::lcdAddr()
{
    return lcd_p;
}

Lcd *Lcd::getInstance()
{
    if(instance == NULL)
    {
        instance = new Lcd;
    }

    return instance;
}


